#include <iostream>
#include <algorithm>
using namespace std;

#define MAX_N 10000
#define MAX_V 10000

int dp[MAX_V + 5];
int v[MAX_N + 5], c[MAX_N + 5];

int main()
{
    int n, V;
    cin >> n >> V;
    for (int i = 1; i <= n; i++)
    {
        cin >> v[i] >> c[i];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= V; j++)
        {
            if (j < v[i])
            {
                continue;
            }
                
            dp[j] = max(dp[j], dp[j - v[i]] + c[i]);
        }
    }
    cout << dp[V] << endl;
    return 0;
}